import { Injectable } from "@nestjs/common";
import { JwtService } from '@nestjs/jwt';
import { InjectRepository } from '@nestjs/typeorm';
import { AdminEntity } from 'src/admin/admin.entity';
import { Repository } from 'typeorm';
import * as argon2 from 'argon2';
import { User } from "src/user/user.interface";
// import { JwtStrategy } from "./jwtStrategy";

@Injectable()
export class AuthService {
  constructor(
    @InjectRepository(AdminEntity)
    private adminRespository: Repository<AdminEntity>,
    private jwtService: JwtService,
    // private jwtStrategy: JwtStrategy,
  ) {}

  valid(pload) {
    console.log(pload);
  }

  validateToken(userinfor: AdminEntity) {
    // 进行用户身份和用户的权限校验
    console.log(userinfor);
    // this.jwtStrategy.validate(token);
    return true;
  }

  public generateJwt(user: User) {
    let today = new Date();
    let exp = new Date(today);

    exp.setDate(today.getDate() + 60);

    return this.jwtService.sign({
      id: user.id,
      username: user.username,
    });
  }
}